/**
 * @Author: 深海有鱼 847094299@qq.com
 * @Date: 2025-04-03 22:51:00
 * @LastEditors: 深海有鱼 847094299@qq.com
 * @LastEditTime: 2025-04-04 18:53:35
 * @FilePath: \pure-admin-thin\src\api\adminServiceTypeApi.ts
 * @Description: 管理员-服务类型管理相关接口
 */

import { http } from "@/utils/http";

/** 1. 根据ID获取服务类型详情 */
export const getServiceTypeById = (id: number) => {
  return http.request<any>("get", `/api/admin/service-types/${id}`);
};

/** 2. 更新服务类型（按ID更新） */
export const updateServiceType = (data: any) => {
  return http.request<any>("put", `/api/admin/service-types/${data.id}`, {
    data
  });
};

/** 3. 设置服务类型状态（按服务类型代码） */
export const setServiceTypeStatus = (code: string, enabled: boolean) => {
  return http.request<any>("put", `/api/admin/service-types/${code}/status`, {
    params: { enabled }
  });
};

/** 4. 设置服务类型的 API 提供商 */
export const setServiceProvider = (code: string, provider: string) => {
  return http.request<any>("put", `/api/admin/service-types/${code}/provider`, {
    params: { provider }
  });
};

/** 5. 设置服务类型排序（批量更新） */
export const updateSortOrder = (sortData: Record<string, number>) => {
  return http.request<any>("put", `/api/admin/service-types/sort`, {
    data: sortData
  });
};

/** 6. 同步服务类型信息 */
export const syncServiceTypes = () => {
  return http.request<any>("post", `/api/admin/service-types/sync`);
};

/** 8. 删除服务类型（自定义类型） */
export const deleteServiceType = (code: string) => {
  return http.request<any>("delete", `/api/admin/service-types/${code}`);
};

/** 9. 上传服务类型图标 */
export const uploadServiceTypeIcon = (code: string, file: File) => {
  const formData = new FormData();
  formData.append("file", file);
  return http.request<any>("post", `/api/admin/service-types/${code}/icon`, {
    data: formData,
    headers: { "Content-Type": "multipart/form-data" }
  });
};

/** 10. 获取所有服务类型 */
export const getAllServiceTypes = (params: {
  onlyEnabled?: boolean | string;
  keyword?: string;
  category?: string;
}) => {
  return http.request<any>("get", `/api/admin/service-types`, {
    params
  });
};

/** 11. 创建服务类型 */
export const createServiceType = (data: any) => {
  return http.request<any>("post", "/api/admin/service-types", { data });
};

/**
 * 切换供应商
 * @param params.serviceCode 服务标准代码，例如 "tg_activate"
 * @param params.targetProvider API 提供商名称（枚举："Apifox API提供商"、"TNT-PUB API提供商"）
 */
export const updateServiceProvider = (
  code: string,
  params: { provider: string }
) => {
  return http.request<any>("put", `/api/admin/service-types/${code}/provider`, {
    params
  });
};
